<template>
  <a-select
    show-search
    option-filter-prop="children"
    :placeholder="$t('pleaseSelect') + $t('activityLevel').toLowerCase()"
    :allow-clean="true"
    :mode="mode"
    :maxTagCount="3"
    v-model="selectedValue"
  >
    <a-select-option v-for="item in options" :key="item.value" :value="item.value">
      {{ item.name }}
    </a-select-option>
  </a-select>
</template>
<script>
//  最近升级成功类型
import { mapState } from 'vuex'
export default {
  props: {
    defaultValue: {
      type: [String, Object],
      default () {
        return null
      }
    },
    mode: {
      type: String,
      default: 'default'
    },
    // 是否含有不限选项
    hasAll: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    ...mapState({
      activityLevels: (state) => state.dict.lastUpgradeSuccessDictCode
    }),
    options () {
      if (this.hasAll) {
        return [{
          value: '',
          name: this.$t('noLimitZ')
        }].concat(this.activityLevels)
      }
      return this.activityLevels
    }
  },
  data () {
    return {
      selectedValue: []

    }
  },
  watch: {
    defaultValue: {
      handler (val) {
        if (val !== this.selectedValue) {
          this.selectedValue = this.defaultValue
        }
      },
      immediate: true
    },
    selectedValue (val) {
      this.$emit('changeoption', val)
    }
  },
  created () {
    this.getData()
  },
  methods: {
    getData () {
      if (this.$store.state.dict.lastUpgradeSuccessDictCode.length === 0) {
        this.$store.dispatch('getLastUpgradeSuccessDictCodeData')
      }
    }
  }
}
</script>
